package com.copractice.data.entity.knowledge;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.copractice.data.entity.PersistentObject;
import com.copractice.data.entity.tag.Tag;
import com.copractice.data.entity.user.User;

/**
 * Represents users knowledge entity.
 *
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/19/2009
 */
@Entity
@Table(name = "USERS_KNOWLEDGE")
@NamedQueries({
        @NamedQuery(name="USERKNOWLEDGE.fetchByUserId",
                    query="select uk from UsersKnowledge uk where uk.id = ?"),
        
        @NamedQuery(name="USERKNOWLEDGE.fetchByUserIdAndTagId",
                    query="select uk from UsersKnowledge uk where uk.user.id = ? and uk.tag.id = ?")
})
@SuppressWarnings("serial")
public class UsersKnowledge extends PersistentObject {

    /**
     * User who owns current knowledge value
     */
    private User user;

    /**
     * Knowledge area which is measured
     */
    private Tag  tag;

    /**
     * Users teaching value
     */
    private Long teachingScore;

    /**
     * Users total score
     */
    private Long totalScore;

    /**
     * Users total possible score
     */
    private Long totalPossibleScore;

    private Long numberQuestions;

    /**
     * @see edu.vt.intelligenttutor.data.entity.PersistentObject#getId()
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Override
    public Long getId() {
        return super.getId();
    }

    @Column(name = "TOTAL_SCORE")
    public Long getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Long totalScore) {
        this.totalScore = totalScore;
    }

    @Column(name = "TOTAL_POSSIBLE_SCORE")
    public Long getTotalPossibleScore() {
        return totalPossibleScore;
    }

    public void setTotalPossibleScore(Long totalPossibleScore) {
        this.totalPossibleScore = totalPossibleScore;
    }

    @Column(name = "NUM_QUES")
    public Long getNumberQuestions() {
        return numberQuestions;
    }

    public void setNumberQuestions(Long numberQuestions) {
        this.numberQuestions = numberQuestions;
    }

    /**
     * Returns <code>User</code> whom knowledge value belong to
     * 
     * @return the <code>User</code> whom knowledge value belong to
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }

    /**
     * Sets <code>User</code> whom knowledge value belong to
     * 
     * @param user
     *            the <code>User</code> whom knowledge value belong to
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Returns knowledge area
     * 
     * @return the <code>Tag</code> which represents knowledge area
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "TAG_ID")
    public Tag getTag() {
        return tag;
    }

    /**
     * Sets knowledge area
     * 
     * @param tag
     *            the <code>Tag</code> which represents knowledge area
     */
    public void setTag(Tag tag) {
        this.tag = tag;
    }

    /**
     * Returns teaching score value
     * 
     * @return the <code>Double</code> which contains teaching score value
     */
    @Column(name = "TEACHING_SCORE")
    public Long getTeachingScore() {
        return teachingScore;
    }

    /**
     * Sets teaching score value
     * 
     * @param value
     *            the <code>Double</code> object holding teaching score value
     */
    public void setTeachingScore(Long teachingScore) {
        this.teachingScore = teachingScore;
    }

}
